package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"mxshop_srvs/goods_srv/proto"
)

var categoryBrandClient proto.GoodsClient
var conn *grpc.ClientConn

func main() {
	Init()
	//TestCreateCategoryBrand()
	//TestUpdateCategoryBrand()
	//TestCategoryBrandList()
	TestGetCategoryBrandList()
	//conn.Close()
}

func TestUpdateCategoryBrand() {
	banner, err := categoryBrandClient.UpdateCategoryBrand(context.Background(), &proto.CategoryBrandRequest{
		Id:         25799,
		CategoryId: 238010,
		BrandId:    1112,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(banner)
}

/*
*
创建banner
*/
func TestCreateCategoryBrand() {
	banner, err := categoryBrandClient.CreateCategoryBrand(context.Background(), &proto.CategoryBrandRequest{
		CategoryId: 238010,
		BrandId:    1114,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(banner)
}

/*
*
测试获取品牌列表
*/
func TestCategoryBrandList() {
	list, err := categoryBrandClient.CategoryBrandList(context.Background(), &proto.CategoryBrandFilterRequest{
		Pages:       1,
		PagePerNums: 15,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(list.Total)
	for _, brand := range list.Data {
		fmt.Println(brand)
	}
}

func TestGetCategoryBrandList() {
	list, err := categoryBrandClient.GetCategoryBrandList(context.Background(), &proto.CategoryInfoRequest{
		Id: 238009,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(list.Total)
	for _, brand := range list.Data {
		fmt.Println(brand)
	}
}

/*
*
删除品牌
*/
func TestDeleteCategoryBrand() {
	brand, err := categoryBrandClient.DeleteCategoryBrand(context.Background(), &proto.CategoryBrandRequest{
		Id:         0,
		CategoryId: 0,
		BrandId:    0,
	})
	if err != nil {
		panic(err)
	}
	fmt.Println(brand)
}

// 初始化
func Init() {
	var err error
	conn, err := grpc.Dial("192.168.31.78:50052", grpc.WithInsecure())
	if err != nil {
		panic(err)
	}
	categoryBrandClient = proto.NewGoodsClient(conn)
}
